package com.bw.find_module.attent;

import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.viewbinding.ViewBinding;

import com.blankj.utilcode.util.LogUtils;
import com.bw.common.entity.LiveDataEntity;
import com.bw.common.mvvm.view.BaseFragment;
import com.bw.find_module.R;
import com.bw.find_module.databinding.FragmentAttentBinding;
import com.bw.find_module.entity.RecommendEntity;
import com.bw.find_module.entity.RecommendValuesEntity;
import com.bw.find_module.entity.hasattent.HasEntity;
import com.bw.find_module.recommend.RecommendAdapter;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class AttentFragment extends BaseFragment<FragmentAttentBinding,AttentViewModel> {

    private AttentAdapter attentAdapter;

    @Override
    public View bindLayout() {
        return v.getRoot();
    }

    @Override
    public ViewBinding initBinding() {
        return FragmentAttentBinding.inflate(inflater);
    }

    @Override
    public void initView() {
        v.attentRecycler.setLayoutManager(new LinearLayoutManager(getContext()));
        EventBus.getDefault().register(this);
        attentAdapter = new AttentAdapter();
        v.attentRecycler.setAdapter(attentAdapter);
    }

    @Override
    public void initData() {
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    public void handleMessage(LiveDataEntity entity) {
        switch (entity.action) {
            case START_VIEW_MODEL:
                RecommendEntity recommendEntity = (RecommendEntity) entity.data.get(LiveDataEntity.LiveDataType.ENTITY);
                attentAdapter.getData().clear();
                attentAdapter.setNewInstance(recommendEntity.data.data);
                break;
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void refreshAttent(String str){
        if (str.equals("refreshAttent")){
            vm.initData();
        }
    }

}
